<?php
/** Copyright 2014 TinPhp Systems, Inc.
 * @author zhangxilian 2013-8-15
 */
if (!defined('IN_TINPHP')) {
	exit ('Access Denied');
}

/**
 * 用户收货地址业务逻辑类
 * 
 * 每个 Logic 对应一个业务逻辑处理单元、必须继承自 BaseLogic
 * 每个 Logic 对应一个或多个 View/DAO
 */
class AddressLogic extends TinBaseLogic {

	private $addressDAO;

	// 每个 Logic 需要有一个构造函数
	public function AddressLogic() {        
		parent::__construct();
		$this->logger->className = "AddressLogic";
		$this->addressDAO = Tin::getDAO("AssignTable","USER_ADDRESS");
	}
	
	public function __destruct(){
		$this->addressDAO = null;
	}
//=========================================收货地址=============================================================
	/** 指定获取单条记录
	 * @author ZhangXiLian 2014-8-29 */
	public function getAddressItem($cols, $cond, $params = false){
		return $this->addressDAO->selectRowByCond($cols, $cond, $params);
	}
	/** 根据指定条件分页获取列表数据 
	 * @author ZhangXiLian 2014-8-29 */
	public function getAddressList($cols, $cond, $order_by  = null, $page = null, $size = null){
        $res = array();
		$res["data"] = $this->addressDAO->selectByCond($cols, $cond . " " . $order_by, $page, $size);
		if ($page){
			$res["count"] = $this->addressDAO->getCountByCond($cond);
		}
		return $res;
	}
	/** 添加收货地址记录
	 * @author ZhangXiLian 2014-8-29 */
	public function addAddressItem($map){
		try{
			$newID = $this->addressDAO->insert($map, false, true);						
			return $newID;
		}catch(Exception $e){
            $this->logger->error("addAddressItem:".$e->getMessage());
			return false;
		}
	}
	/** 根据指定条件更新记录
	 * @author ZhangXiLian 2014-8-29 */
	public function updateAddressByCond($map, $cond){
		try{
            $res = $this->addressDAO->updateByCond($map, $cond, false);            
            return $res;
        } catch(Exception $e){
            $this->logger->error("updateAddressByCond:".$e->getMessage());
            return false;
        }
	}

}//End Class
?>
